package com.qiwo.common.config;

import com.alibaba.fastjson.JSONObject;
import com.qiwo.common.domain.ContentDO;
import com.qiwo.common.service.ContentService;
import com.qiwo.common.utils.SpringContextHolder;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.ui.ConcurrentModel;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ModelAttribute;

import java.util.HashMap;
import java.util.Map;

/**
 * Copyright
 *
 * @Author:chenwenchao
 * @Date:2018/10/27 0027
 * Description:
 */
@ControllerAdvice
public class GlobalModelData {

    @Value("${company.seotitle}")
    private String title;
    @ModelAttribute
    public ConcurrentModel globalSEO() {
        ConcurrentModel jsonObject=new ConcurrentModel();
        jsonObject.addAttribute("seotitle",title);
        jsonObject.addAttribute("seokeywords",title);
        ContentService contentService= SpringContextHolder.getApplicationContext().getBean(ContentService.class);
        ContentDO contentDO=contentService.findOneByKv("type_id",6);
        jsonObject.addAttribute("golbalTel",contentDO.getTitle());
        jsonObject.addAttribute("qq",contentDO.getEnTitle());
        jsonObject.addAttribute("WeiChatImg",contentDO.getImageUrl());
        jsonObject.addAttribute("companyName",contentDO.getCompanyName());
        jsonObject.addAttribute("companyAddress",contentDO.getCompanyAddress());
        jsonObject.addAttribute("weiboAddress",contentDO.getTitle2());
        jsonObject.addAttribute("rigthtTel",contentDO.getEnTitle2());
        jsonObject.addAttribute("latitude",contentDO.getLatitude());
        jsonObject.addAttribute("longitude",contentDO.getLongitude());
        jsonObject.addAttribute("copyright",contentDO.getContent());
        return jsonObject;
    }
}
